import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/message/message_config.dart';
import 'package:ls_work/model/service_order/service_order_model.dart';
import 'package:ls_work/net/response/department_list_data.dart';

import '../../net/response/service_order_ddetail_data.dart';
import '../../ui/send_order/select_employee_page.dart';
import '../../ui/service_order/department_list_page.dart';
import '../service_order/service_order_detail_info_view_model.dart';

class SendOrderViewModel extends BaseViewModel{
  SendOrderViewModel(BuildContext context) : super(context);

  ServiceOrderDdetailData get detailData  => ServiceOrderDetailInfoViewModel.detailData!;

  var model = ServiceOrderModel();

  var departmentName = "";
  var departmentId = "";
  var personName = "";
  var personId = "";

  Future<void> selectDepartment() async {
    var data = await Go().push(SelectEmployeePage());
    if (data != null) {
      departmentName = data['departmentName'];
      departmentId = data['departmentId'];
      personName = data['employeeName'];
      personId = data['employeeId'];
      notifyListeners();
    }
  }


  Future<void> sendOrder() async {
    if(departmentId.isNullOrEmpty()){
      showToast("请选择责任人");
      return;
    }
    showLoadingDialog(msg: '提交中...');
    try{
      var data = await model.sendOrder(personId, departmentId,detailData.id.toString());
      showToast("派单成功");
      sendMessage(SendMessageEvent(MessageConfig.REFRESH_ORDER));
      finish();
      finish();
    }catch(e){
      hideDialog();
      print(e);
      showToast(NetErrorUtils.getNetError(e));
    }
  }

}
